﻿# This Python file uses the following encoding: utf-8
import sys, argparse
import pandas as pd
from PySide2.QtCore import QDateTime, QTimeZone


def transform_date(utc, timezone=None):
    utc_fmt = "yyyy-MM-ddTHH:mm:ss.zzzZ"
    new_date = QDateTime().fromString(utc, utc_fmt)
#    print (new_date.toString(utc_fmt))
    if timezone:
        new_date.setTimeZone(timezone)

    return new_date

def read_data(fname):
    df = pd.read_csv(fname)

    #移除错误的mag
    df = df.drop(df[df.mag < 0].index)
    magnitudes = df["mag"]

    #本地时区
    timezone = QTimeZone(b"Asia/Beijing")

    #将时间戳转换为本地时区
    times = df["time"].apply(lambda x: transform_date(x, timezone))

    return times, magnitudes


if __name__ == "__main__":
    options = argparse.ArgumentParser()
    options.description = "过滤csv信息"
    options.add_argument("-f", "--file", type=str, required=True, help="CSV文件路径")
    args = options.parse_args()
    data = read_data(args.file)
    print (data)
